package com.search.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


import com.alibaba.fastjson.JSON;
import com.search.pojo.Leaveparkinfo;
import com.search.pojo.Scenicsinfo;
import com.search.pojo.Spotscheckinfo;
import com.search.pojo.Spotsinfo;
import com.search.pojo.Spotssaleinfo;
import com.search.pojo.Statinfo;
import com.search.pojo.TotalResult;
import com.search.pojo.Webcheckinfo;
import com.search.pojo.Weborderinfo;
import com.search.service.HttpMessage;
import com.search.utils.HttpClientUtil;
import com.search.utils.MyDigestUtil;
/**
 * 
 * @author liujun
 *
 */
@Component
public class HttpMessageImpl implements HttpMessage{
	@Value("${appkey}")
	private  String appkey;
	@Value("${headUrl}")
	private  String headUrl;
	@Value("${areaCode}")
	private String areaCode;
	@Value("${appCode}")
	private String appCode;
	
	/**
	 * 获取该区域下所有景区接口
	 * @author liujun
	 */
	@Override
	public String getScenicsInfo() {
		Map<String,String> mapTree =new TreeMap<>();
		 String url=headUrl+"getScenicsInfo.htm";
		 mapTree.put("areaCode", areaCode);
		 mapTree.put("appCode", appCode);
		 String sign =MyDigestUtil.md5Digest("areaCode="+areaCode);
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 //System.out.println("result:"+result);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 int t=0;
		 if("SUCCESS".equals(tt.getResult())){
			 List<Scenicsinfo> list =JSON.parseArray(tt.getData(), Scenicsinfo.class);
		 }else{
			 throw new RuntimeException(tt.getMessage());
		 }
		 return String.valueOf(t);
	}
	/**
	 * 查询景区下景点
	 */
	@Override
	public String getSpotsInfo(String groupCode) {
		Map<String,String> mapTree =new TreeMap<>();
		 String url=headUrl+"getSpotsInfo.htm";
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("appCode", appCode);
		 String sign =MyDigestUtil.md5Digest("groupCode="+groupCode);
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 //System.out.println("result:"+result);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 int t=0;
		 if("SUCCESS".equals(tt.getResult())){
			 List<Spotsinfo> list =JSON.parseArray(tt.getData(), Spotsinfo.class);
		 }else{
			 throw new RuntimeException(tt.getMessage());
		 }
		 return String.valueOf(t);
	}
	/**
	 * 查询线下景点售票信息
	 */
	@Override
	public List<Spotssaleinfo> getSpotsSaleInfo(String beginTime, String endTime, 
									String groupCode, String parkCode) {
		
		Map<String,String> mapTree =new TreeMap<>();
		 String url=headUrl+"getSpotsSaleInfo.htm";
		 mapTree.put("beginTime", beginTime);
		 mapTree.put("endTime", endTime);
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("parkCode", parkCode);
		 mapTree.put("appCode", appCode);
		 StringBuffer sb =new StringBuffer("");
		 sb.append("beginTime=");
		 sb.append(beginTime);
		 sb.append("&endTime=");
		 sb.append(endTime);
		 sb.append("&groupCode=");
		 sb.append(groupCode);
		 sb.append("&parkCode=");
		 sb.append(parkCode);
		 //System.out.println("test:"+sb.toString());
		 String sign =MyDigestUtil.md5Digest(sb.toString());
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 //System.out.println("result:"+result);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 List<Spotssaleinfo> list =null;
		 if("SUCCESS".equals(tt.getResult())){
			  list =JSON.parseArray(tt.getData(), Spotssaleinfo.class);
		 }else{
			 throw new RuntimeException(tt.getMessage());
		 }
		 return list;
	}
	/**
	 * 查询线下景点检票信息
	 */
	@Override
	public String getSpotsCheckInfo(String beginTime, String endTime, String groupCode, String parkCode) {
		Map<String,String> mapTree =new TreeMap<>();
		 String url=headUrl+"getSpotsCheckInfo.htm";
		 mapTree.put("beginTime", beginTime);
		 mapTree.put("endTime", endTime);
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("parkCode", parkCode);
		 mapTree.put("appCode", appCode);
		 StringBuffer sb =new StringBuffer("");
		 sb.append("beginTime=");
		 sb.append(beginTime);
		 sb.append("&endTime=");
		 sb.append(endTime);
		 sb.append("&groupCode=");
		 sb.append(groupCode);
		 sb.append("&parkCode=");
		 sb.append(parkCode);
		 //System.out.println("test:"+sb.toString());
		 String sign =MyDigestUtil.md5Digest(sb.toString());
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 //System.out.println("result:"+result);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 int t=0;
		 if("SUCCESS".equals(tt.getResult())){
			 List<Spotscheckinfo> list =JSON.parseArray(tt.getData(), Spotscheckinfo.class);
		 }else{
			 throw new RuntimeException(tt.getMessage());
		 }
		 return String.valueOf(t);
	}
	/**
	 * 电子订单交易
	 */
	@Override
	public String getWebOrderInfo(String beginTime, String endTime, String groupCode) {
		
		Map<String,String> mapTree =new TreeMap<>();
		 String url=headUrl+"getWebOrderInfo.htm";
		 mapTree.put("beginTime", beginTime);
		 mapTree.put("endTime", endTime);
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("appCode", appCode);
		 StringBuffer sb =new StringBuffer("");
		 sb.append("beginTime=");
		 sb.append(beginTime);
		 sb.append("&endTime=");
		 sb.append(endTime);
		 sb.append("&groupCode=");
		 sb.append(groupCode);
		 String sign =MyDigestUtil.md5Digest(sb.toString());
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 //System.out.println("result:"+result);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 int t=0;
		 if("SUCCESS".equals(tt.getResult())){
			 List<Weborderinfo> list =JSON.parseArray(tt.getData(), Weborderinfo.class);
			 
		 }else{
			 throw new RuntimeException(tt.getMessage());
		 }
		 return String.valueOf(t);
	}
	/**
	 * 电子订单使用信息
	 */
	@Override
	public String getWebCheckInfo(String beginTime, String endTime, String groupCode) {
		Map<String,String> mapTree =new TreeMap<>();
		 String url=headUrl+"getWebCheckInfo.htm";
		 mapTree.put("beginTime", beginTime);
		 mapTree.put("endTime", endTime);
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("appCode", appCode);
		 StringBuffer sb =new StringBuffer("");
		 sb.append("beginTime=");
		 sb.append(beginTime);
		 sb.append("&endTime=");
		 sb.append(endTime);
		 sb.append("&groupCode=");
		 sb.append(groupCode);
		 String sign =MyDigestUtil.md5Digest(sb.toString());
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 //System.out.println("result:"+result);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 int t=0;
		 if("SUCCESS".equals(tt.getResult())){
			 List<Webcheckinfo> list =JSON.parseArray(tt.getData(), Webcheckinfo.class);
		 }else{
			 throw new RuntimeException(tt.getMessage());
		 }
		 return String.valueOf(t);
	}
	/**
	 * 实时统计信息
	 */
	@Override
	public List<Statinfo> getStatInfo(String beginTime, String endTime, String groupCode) {
		Map<String,String> mapTree =new TreeMap<>();
		 String url=headUrl+"getStatInfo.htm";
		 mapTree.put("beginTime", beginTime);
		 mapTree.put("endTime", endTime);
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("appCode", appCode);
		 StringBuffer sb =new StringBuffer("");
		 sb.append("beginTime=");
		 sb.append(beginTime);
		 sb.append("&endTime=");
		 sb.append(endTime);
		 sb.append("&groupCode=");
		 sb.append(groupCode);
		 String sign =MyDigestUtil.md5Digest(sb.toString());
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 //System.out.println("result:"+result);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 List<Statinfo> list =new ArrayList<>();
		 if("SUCCESS".equals(tt.getResult())){
			 list=JSON.parseArray(tt.getData(), Statinfo.class);
		 }else{
			 throw new RuntimeException(tt.getMessage());
		 }
		 return list;
	}
	@Override
	public String getLeaveParkInfo(String beginTime, String endTime, String groupCode) {
		
		Map<String,String> mapTree =new TreeMap<>();
		 String url=headUrl+"getLeaveParkInfo.htm";
		 mapTree.put("beginTime", beginTime);
		 mapTree.put("endTime", endTime);
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("appCode", appCode);
		 StringBuffer sb =new StringBuffer("");
		 sb.append("beginTime=");
		 sb.append(beginTime);
		 sb.append("&endTime=");
		 sb.append(endTime);
		 sb.append("&groupCode=");
		 sb.append(groupCode);
		 String sign =MyDigestUtil.md5Digest(sb.toString());
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 //System.out.println("result:"+result);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 int t=0;
		 if("SUCCESS".equals(tt.getResult())){
			 List<Leaveparkinfo> list =JSON.parseArray(tt.getData(), Leaveparkinfo.class);
		 }else{
			 throw new RuntimeException(tt.getMessage());
		 }
		 return String.valueOf(t);
	}
	

}
